/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {
    mysql: {
      client: {
        host: '127.0.0.1',
        port: '3306',
        user: 'root',
        password: 'H123456789',
        database: 'loaf-community',
      },
      app: true,
      agent: false,
    },
  });

  config.keys = appInfo.name + '_1637556324610_7094';

  config.middleware = ['errorHandler', 'tokenHandler'];

  config.errorHandler = {
    match: '/api',
  };

  config.tokenHandler = {
    match(ctx) {
      const url = ctx.request.url;
      if (url.startsWith('/api/v1/login') || url.startsWith('/api/v1/register') || url.startsWith('/image'))
        return false;
      return true;
    },
  };

  config.jwt = {
    secret: '123456',
    enable: true,
    sign: {
      expiresIn: 2 * 60 * 60 + 's',
    },
    match(ctx) {
      const url = ctx.request.url;
      if (url.startsWith('/api/v1/login') || url.startsWith('/api/v1/register') || url.startsWith('/image'))
        return false;
      return true;
    },
  };

  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    domainWhiteList: ['http://localhost:8080'],
  };

  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };

  config.multipart = {
    fileSize: '5mb',
    mode: 'stream',
    fileExtensions: ['.jpg', 'jpeg', '.png', 'gif', 'jfif'],
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
